package com.example.widget_lib.widget;

import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.utils.Color;
import ohos.app.Context;

/**
 * 图例样式
 *
 * @autor hongbing
 * @date 2018/12/20
 */
public class PointView extends Component implements Component.DrawTask {


    private Paint mPaint;
    private int mStyle;
    private Color mColor = Color.RED;
    private int mPointWH;

    public PointView(Context context) {
        this(context, null);
    }

    public PointView(Context context, AttrSet attrs) {
        this(context, attrs, 0);
    }

    public PointView(Context context, AttrSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mPaint = new Paint();
//        Paint.ANTI_ALIAS_FLAG
        mPaint.setAntiAlias(true);
        mPaint.setStyle(Paint.Style.FILL_STYLE);
        addDrawTask(this);
    }

    public void setStyle(int style) {
        mStyle = style;
    }

    public void setColor(Color color) {
        mColor = color;
        invalidate();
    }

    public void setPointWH(int wh) {
        mPointWH = wh;
        invalidate();
    }

    @Override
    public void onDraw(Component component, Canvas canvas) {
        mPaint.setColor(mColor);
        if (mStyle == Point_Style.CIRCLE) {
            canvas.drawCircle(mPointWH / 2, mPointWH / 2, mPointWH / 2, mPaint);
        } else if (mStyle == Point_Style.SQUARE) {
            mPaint.setStrokeWidth(12);
            canvas.drawPoint(0, mPointWH / 2, mPaint);
        } else {

        }
    }

    @Override
    public void addDrawTask(DrawTask task) {
        super.addDrawTask(task);
        task.onDraw(this, mCanvasForTaskOverContent);
    }

    public interface Point_Style {
        int CIRCLE = 0;
        int SQUARE = 1;
        int LINE = 2;
    }
}
